<?php
namespace Admin\Controller;
use Think\Controller;
class MemberController extends BaseController {
    
	protected function _initialize(){
		parent::_initialize();
	}
	
	//会员管理
	public function index(){
		//会员
	}
	
	//会员列表
	public function memberlist(){
		$m=M('client_user');
		$p=$_GET['p']?$_GET['p']:1;
		$psize=C('BB_PSIZE')?C('BB_PSIZE'):20;
		if(I('name')){
			$search=I('name');
			$map['name']=array('like',"%$search%");
			$map['username'] = array('like',"%$search%");
			$map['_logic'] = 'OR';
		}
		$data=$m->where($map)->page($p,$psize)->order('addtime desc')->select();
		$count=$m->where($map)->count();
		$this->getPage($count, $psize, 'bb-loader', '会员管理','bb-search');
		foreach ($data as $k => $v){
			$wxuser=M('weixin_client_user')->field('headimgurl')->where(array('openid'=>$v['openid']))->find();
			$data[$k]['headimgurl']=$wxuser['headimgurl'];
		}
		$this->assign('cache',$data);
		$this->display();
	}
	
	public function memberset(){
		$m=M('client_user');
		$id=I('id');
		$cache=$m->find($id);
		$this->assign('cache',$cache);
		$this->display();
	}
	
	//删除黑名单
	public function memberdel(){
		$id=I('id');
		if($id){
			M('bps_user')->delete($id);
			if($re){
				$info['status']=1;
				$info['msg']='删除成功!';
			}else{
				$info['status']=0;
				$info['msg']='删除失败!';
			}
			$this->ajaxreturn($info);
		}
	}
	
	
	public function del_f(){
		$m=M('client_user');
		$id=I('id');
		if($id){
			$re=$m->delete($id);
			if($re){
				$info['status']=1;
				$info['msg']='删除成功！';
			}else{
				$info['status']=0;
				$info['msg']='删除失败！';
			}
		}else{
			$info['status']=0;
			$info['msg']='删除失败！';
		}
		$this->ajaxreturn($info);
	}
	
	
	public function domemberset(){
		if($_POST['id']){
			$data['username']=$_POST['username'];
			$data['name']=$_POST['name'];
			$data['phone']=$_POST['phone'];
			$data['address']=$_POST['address'];
			$data['notice']=$_POST['statnoticeus'];
			$notice = M('client_user');
			$cache = $notice->where('id = '.$_POST['id'])->save($data);
			if($cache){
				$info['status']=1;
						$info['msg']='修改成功！';
			}else{
				$info['status']=0;
						$info['msg']='修改失败！';
			}
			$this->ajaxreturn($info);
	
		}
		
		
		
		
		
	}
	
}